//
//  MyService.m
//  WisdomStar
//
//  Created by 谭飞 on 2018/11/12.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "MyService.h"

#import "GetUserInfoAPI.h"
#import "MyVerifyAPI.h"
#import "LessonTicketAPI.h"
#import "GetMyScoreAPI.h"
#import "ScoreExchangeAPI.h"

@implementation MyService


/**
 获取用户信息

 @param complete call back
 */
+ (void)fetchUserInfoCompletion:(void (^)(id _Nonnull))complete {
    GetUserInfoAPI *api = [[GetUserInfoAPI alloc] init];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(request.responseObject);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(request.responseObject);
    }];
}


/**
 提交认证

 @param type 认证类型
 @param complete call back
 */
+ (void)commitVerifyRequestWithType:(NSInteger)type params:(nonnull id)params completion:(nonnull void (^)(BOOL, id _Nonnull))complete {
    MyVerifyAPI *api = [[MyVerifyAPI alloc] init];
    api.verifyType = type;
    api.outerParameters = params;
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(true, request.responseObject);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        IOAResponse *response = [IOAResponse responseWithRequest:request];
        [SVProgressHUD showError:response.responseMessage];
        complete(false, request.responseObject);
    }];
}


/**
 获取我的课时券

 @param result call back
 */
+ (void)fetchLessonTicketWithResult:(void (^)(id _Nonnull))result {
    LessonTicketAPI *api = [[LessonTicketAPI alloc] init];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        result(request.responseObject);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        result(request.responseObject);
    }];
}


/**
 获取我的积分

 @param result call back
 */
+ (void)fetchMyScoresWithResult:(void (^)(id _Nonnull))result {
    GetMyScoreAPI *api = [[GetMyScoreAPI alloc] init];
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        result(request.responseObject);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        result(request.responseObject);
    }];
}


/**
 积分兑换

 @param params params
 @param complete call back
 */
+ (void)exchangeWithParams:(id)params completion:(void (^)(BOOL))complete {
    ScoreExchangeAPI *api = [[ScoreExchangeAPI alloc] init];
    api.outerParameters = params;
    [api startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        complete(true);
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        IOAResponse *response = [IOAResponse responseWithRequest:request];
        [SVProgressHUD showError:response.responseMessage];
        complete(false);
    }];
}

@end
